package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.PageHelper;
import sy.pageModel.Trace;
import sy.service.TraceServiceI;

import javax.servlet.http.HttpSession;


/**
 * 监控ACTION
 * 
 * @author
 * 
 */
@Controller
@RequestMapping("/traceController")
public class TraceController extends BaseController {
	@Autowired
	private TraceServiceI traceServiceI;
	
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(Trace trace, PageHelper ph) {
		return traceServiceI.dataGrid(trace, ph);
	}


	@RequestMapping("/traceDetailAdd")
	public String traceDetailAdd() {
		return "/business/traceDetailAdd";
	}
	
	
	/**
	 * 跳转到traceDetial管理页面
	 * 
	 * @return
	 */

	@RequestMapping("/add")
	@ResponseBody
	public Json add(Trace trace) {
		Json j = new Json();
		try {
			traceServiceI.add(trace);
			j.setSuccess(true);
			j.setMsg("添加成功！");
			j.setObj(trace);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Json delete(String id) {
		Json j = new Json();
		traceServiceI.delete(id);
		j.setMsg("删除成功！");
		j.setSuccess(true);
		return j;
	}

	@RequestMapping("/batchDelete")
	@ResponseBody
	public Json batchDelete(String ids) {
		Json j = new Json();
		if (ids != null && ids.length() > 0) {
			for (String id : ids.split(",")) {
				if (id != null) {
					this.delete(id);
				}
			}
		}
		j.setMsg("批量删除成功！");
		j.setSuccess(true);
		return j;
	}
	
}
